package com.situ.blog.controller;

import com.situ.blog.pojo.Blog;
import com.situ.blog.service.IBlogService;
import com.situ.blog.util.JSONResult;
import com.situ.blog.util.LayUITableJSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/blog")
public class BlogController {
    @Autowired
    private IBlogService blogService;

    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer id) {
        return blogService.deleteById(id);
    }

    @RequestMapping("/add")
    @ResponseBody
    public JSONResult add(Blog blog) {
        //JSONResult jsonResult = blogService.add(blog);
        //return jsonResult;

        return blogService.add(blog);
    }

    @RequestMapping("/getBlogAddPage")
    public String getBlogAddPage() {
        return "/WEB-INF/blog_add.jsp";
    }

    @RequestMapping("/getBlogListPage")
    public String getBlogListPage() {
        return "/WEB-INF/blog_list.jsp";
    }

    // /blog/selectByPage?page=1&limit=10
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableJSONResult selectByPage(Integer page, Integer limit) {
        LayUITableJSONResult layUITableJSONResult = blogService.selectByPage(page, limit);
        return layUITableJSONResult;
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Blog> selectAll() {
        List<Blog> list = blogService.selectAll();
        return list;
    }
}
